#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int n, m;
int cnt[N], a[N], cur;
int ans[N];
int pos[N], b[N];

struct qry {
	int l, r, t, bl, br, id;
} t[N];

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; int B = pow(n, 1. * 2 / 3);
	rep(i, 1, n) a[i] = in;
	int tim = 0, tot = 0;
	rep(i, 1, m) {
		char ch = getchar(); while(!isalpha(ch)) ch = getchar();
		if(ch == 'Q') {
			++tot; t[tot].l = in, t[tot].r = in, t[tot].t = tim; t[tot].id = tot;
			t[tot].bl = (t[tot].l - 1) / B + 1; t[tot].br = (t[tot].r - 1) / B + 1;
		} else {
			++tim; pos[tim] = in, b[tim] = in;
		}
	}
	sort(t + 1, t + tot + 1, [&](auto x, auto y) {
		return x.bl ^ y.bl ? x.bl < y.bl : x.br ^ y.br ? x.bl & 1 ? x.br < y.br : x.br > y.br : x.t < y.t;
	});
	int l = 1, r = 0; tim = 0;
	rep(i, 1, tot) {
		auto x = t[i];
		while(r < x.r) // r++, cnt[a[r]]++, ans += cnt[a[r]] == 1;
			cur += !cnt[a[++r]]++;
		while(r > x.r)
			cur -= !--cnt[a[r--]];
		while(l > x.l)
			cur += !cnt[a[--l]]++;
		while(l < x.l)
			cur -= !--cnt[a[l++]];
		while(tim < x.t) {
			++tim;
			if(pos[tim] >= l && pos[tim] <= r) cur -= !--cnt[a[pos[tim]]];
			swap(a[pos[tim]], b[tim]);
			if(pos[tim] >= l && pos[tim] <= r) cur += !cnt[a[pos[tim]]]++;
		}
		while(tim > x.t) {
			if(pos[tim] >= l && pos[tim] <= r) cur -= !--cnt[a[pos[tim]]];
			swap(a[pos[tim]], b[tim]);
			if(pos[tim] >= l && pos[tim] <= r) cur += !cnt[a[pos[tim]]]++;
			--tim;
		}
		ans[x.id] = cur;
	} rep(i, 1, tot) printf("%d\n", ans[i]); 
	return 0;
}
